import logging
import sys
import os
import time

def get_logger(name):
	if not os.path.exists('log'):
		os.mkdir('log')
	cur = 'log' + os.sep + time.strftime('%Y%m%d',time.localtime(time.time())) + '.log'

	logger = logging.getLogger(name)

	fmt = '%(asctime)s %(levelname)-8s: %(message)s'
	formatter = logging.Formatter(fmt)

	file_handler = logging.FileHandler(cur,encoding='utf-8')
	file_handler.setFormatter(formatter)

	console_handler = logging.StreamHandler()
	console_handler.formatter = formatter

	logger.addHandler(file_handler)
	logger.addHandler(console_handler)    

	logger.setLevel(logging.INFO)

	return logger

if __name__ == '__main__':
	logger = get_logger('test')
	logger.info('test')
	logger.warning('123')
	logger.info('456')
    